package main

import (
	"fmt"
	"reflect"
)

// 反射练习
func testReflect(i interface{}) {
	//转为reflect。type
	rtyp := reflect.TypeOf(i)
	fmt.Printf("%v====%T", rtyp, rtyp)
	fmt.Println()

	//转为reflect.value
	rval := reflect.ValueOf(i)
	fmt.Printf("%v=====%T", rval, rval)
	fmt.Println()
	//再转为原来接口类型
	orgin := rval.Interface()
	//类型断言
	i3 := orgin.(int)
	fmt.Println(i3)
	fmt.Printf("%T", orgin)
	fmt.Println()
	num := 10
	i2 := rval.Int()
	num += int(i2)
	fmt.Println(num)

}

/**
输出结果展示
*/
//int====*reflect.rtype
//120=====reflect.Value
//120
//int
//130

func main() {
	var num int = 120
	testReflect(num)
}
